<template>
  <div>
    <div class="button_box_jb button_box_jb_w" style="margin-right: 0">
      <div
        class="zc"
        @click="Submit()"
        v-if="
          infostate == 0 || infostate == 5 || infostate == 2 || infostate == 3
        "
      >
        暂存
      </div>
      <div class="hs" v-if="infostate == 1">公示中</div>
      <div class="hs" v-if="infostate == 2">审核中</div>
      <div class="zc" v-if="infostate == 1 || infostate == 6" @click="update()">
        申请修改
      </div>
      <div class="zc" v-if="infostate == 4">已申请修改</div>
      <div class="xyb" @click="next()">下一步</div>
    </div>
   
    <div class="item_box_jbxx">
      <el-collapse v-model="activeNames">
        <el-collapse-item title="机构基本信息" name="1">
          <list ref="childComp" :column="2" :list.sync="FormData.list"> </list>
        </el-collapse-item>
        <el-collapse-item title="通讯信息" name="2" class="s2">
          <list ref="childComp" :column="2" :list.sync="FormData.txlist">
          </list>
        </el-collapse-item>
        <el-collapse-item title="发票信息" name="3" class="s1">
          <list ref="childComp" :column="2" :list.sync="FormData.fplist">
          </list>
        </el-collapse-item>
      </el-collapse>
    </div>
    <div class="button_box_jb">
      <div
        class="zc"
        @click="Submit()"
        v-if="
          infostate == 0 || infostate == 5 || infostate == 2 || infostate == 3
        "
      >
        暂存
      </div>
      <div class="hs" v-if="infostate == 1">公示中</div>
      <div class="hs" v-if="infostate == 2">审核中</div>
      <div class="zc" v-if="infostate == 1 || infostate == 6" @click="update()">
        申请修改
      </div>
      <div class="zc" v-if="infostate == 4">已申请修改</div>
      <div class="xyb" @click="next()">下一步</div>
    </div>
  </div>
</template>

<script>
import list from "../../components/list.vue";
import { mapState, mapMutations } from "vuex";

export default {
  data() {
    return {
      activeNames: ["1", "2", "3"], //展开的页面
      infostate: 0, //信息的状态
      vmodel: [
        "name", // 机构全称
        "legal_name", // 法定代表人
        "reg_code", // 注册登记号（会员）
        "unify_code", // 统一社会信用代码
        "business", // 工商登记机关
        "business_circles", // 不动产登记代理机构证书号
        "valuer_code",//土地估价机构备案函号
        "reg_money", // 注册资金（万元）
        "company_type", // 企业类型值
        "legal_mobile", // (tax原税务登记号)法定代表人电话
        "establishment_date", // 成立时间，格式2023-01-01
        "mobile", // 办公电话
        "license_date", // 营业期限
        "phone", // 负责人电话
        "email", // 电子信箱
        "zip_code", // 邮政邮编
        "address", // 机构地址
        "fax", // 传真
        "communicate_name", // 通讯信息负责人姓名（新加的）
        "communicate_mobile", // 通讯信息负责人电话
        "communicate_tel", // 通讯信息固定电话
        "communicate_email", // 通讯信息邮箱
        "communicate_zip_code", // 通讯信息邮编
        "communicate_address", // 通讯信息地址
        "invoice_company", // 发票信息单位
        "invoice_unify_code", //统一社会信用代码
        "invoice_email", // （原发票信息电话）邮箱
        "invoice_mobile", // （原发票信息税号）办公电话（跟着上面变）
        "invoice_account", // 发票信息账号
        "invoice_bank", // 发票信息开户行
        "invoice_address", // （invoice_address原发票信息）地址（跟着上面机构地址变）
      ],
    };
  },

  components: {
    list: list,
  },
  computed: {
    ...mapState({
      FormData: (state) => state.FormData,
    }),
   
  },
  mounted() {
    this.getclass();
    this.getinfostate();
  },
  methods: {
    ...mapMutations(["sethymenulist"]),

    /**
     * 获取信息状态
     */
    getinfostate() {
      let that = this;
      let data = {};
      that.$http.post("mechanism/check_publicity", data).then((res) => {
        if (res.code == 1) {
          that.infostate = res.data.status;

          if (
            this.infostate == 0 ||
            this.infostate == 2 ||
            this.infostate == 5 ||
            this.infostate == 3
          ) {
          } else {
            this.sethymenulist(false);
          }
          // that.infostate = 2;
          for (let prop in that.FormData) {
            that.FormData[prop].forEach((item, index) => {
              if (
                that.infostate == 1 ||
                that.infostate == 4 ||
                that.infostate == 6
              ) {
                item.disabled = true;
              } else {

                if (item.name == "会员号" || item.name == "不动产登记代理机构证书号" || item.name == "土地估价机构备案函号") {
                  item.disabled = true;
                } else {
                  item.disabled = false;
                }
                //判断通讯信息时禁用哪些输入
                if(prop=='txlist'){
                  if (
                    item.name == "联系人电话"||
                    item.name == "通讯邮箱"||
                    // item.name == "地址"||
                    item.name == "邮政编码"
                    // ||
                    // item.name == "邮编"
                  ) {
                    item.disabled = true;
                  } else {
                    
                  }
                }
                //判断发票信息时禁用哪些输入
                if(prop=='fplist'){
                  if (
                    item.name == "机构全称"||
                    item.name == "社会统一信用代码"||
                    item.name == "通讯邮箱"||
                    item.name == "办公电话"||
                    item.name == "通讯地址"
                  ) {
                    item.disabled = true;
                  } else {
                    
                  }
                }
              }
            });
          }
        }
      });
    },
    /**
     * 申请修改
     */
    update() {
      let that = this;
      let data = {};
      let msgg = {
        code: "",
        msg: "",
      };
      that.$http.post("mechanism/apply_edit", data).then((res) => {
        msgg.code = res.code;
        if (res.code == 1) {
          msgg.msg = res.msg + "，请前往站内通知查看审核信息";
        } else {
          msgg.msg = res.msg;
        }
        // console.log(msgg)
        that.$self
          .ts(msgg, 2)
          .then(() => {
            this.$router.push({ path: "/hyzntz" });
          })
          .catch(() => {
            that.getinfostate();
          });
      });
    },
    /**
     * 获取机构企业类型
     */
    getclass() {
      let that = this;
      let data = {};
      that.$http.post("mechanism/company_type", data).then((res) => {
        that.FormData.list.forEach((item, index) => {
          if (item.type == "select") {
            // console.log(item);
            item.value = res.data[0].value;
            item.list = res.data;
          }
        });
        this.getinfo();
      });
    },
    /**
     * 获取机构基本信息
     */
     getinfo() {
      let that = this;
      let data = {
        type: "basic",
      };
      that.$http.post("mechanism/list", data).then((res) => {
        let obj = JSON.parse(JSON.stringify(res.data.basic));

        let obj_fz = JSON.parse(JSON.stringify(res.data.basic));//赋值
        // console.log(obj_fz)
        if (!obj.invoice_mobile) {
          obj.invoice_mobile = obj_fz.phone;
        }
        if (!obj.mobile) {
          obj.mobile = obj_fz.phone;
        }
        if (!obj.communicate_mobile) {
          obj.communicate_mobile = obj_fz.phone;
        }
        if (!obj.communicate_tel) {
          obj.communicate_tel = obj_fz.phone;
        }
        if (!obj.legal_mobile) {
          obj.legal_mobile = obj_fz.phone;
        }
        if (!obj.invoice_company) {
          obj.invoice_company = obj_fz.name;
        }
        if (!obj.communicate_email) {
          obj.communicate_email = obj_fz.email;
        }
        if (!obj.invoice_email) {
          obj.invoice_email = obj_fz.email;
        }
        if(obj.mobile){
          // obj.communicate_mobile=obj.mobile
          obj.invoice_mobile=obj.mobile
        }
        if(obj.phone){
          obj.communicate_mobile=obj.phone
          // obj.invoice_mobile=obj.phone
        }
        if (obj.unify_code) {
          obj.invoice_unify_code = obj_fz.unify_code;
        }
        // 邮箱使用一个字段
        if (obj.email) {
          obj.communicate_email = obj_fz.email;
          obj.invoice_email = obj_fz.email;
        }
        // if(obj.address){
        //   obj.communicate_address=obj_fz.address
        //   obj.invoice_address = obj_fz.address;
        // }
        if(obj.communicate_address){
          obj.invoice_address = obj_fz.communicate_address;
        }
        if(obj.zip_code){
          obj.communicate_zip_code=obj_fz.zip_code
        }
        this.$self.getdata(this.FormData, obj, this.vmodel);
      });
    },
    /**
     * 暂存
     */
    Submit() {
      let that = this;
      let data = this.$self.Submit(this.FormData, this.vmodel);
      // console.log(data)
      that.$http.post("mechanism/basic_remain", data).then((res) => {
        that.$self.ts(res).then(() => {
          that.getinfostate();
          that.getinfo()
        });
      });
    },
    /**
     * 下一步
     */
    next() {
      let that = this;
      let data = that.$self.Submit(that.FormData, that.vmodel);
      if (
        that.infostate == 0 ||
        that.infostate == 2 ||
        that.infostate == 5 ||
        that.infostate == 3
      ) {
        that.$http.post("mechanism/basic_remain", data).then((res) => {
          that.$self.ts(res).then(() => {
            that.$router.push({
              path: "/hygdxx",
              query: { infostate: that.infostate },
            });
          });
        });
      } else {
        that.$router.push({
          path: "/hygdxx",
          query: { infostate: that.infostate },
        });
      }
    },
    //  ==
  },
};
</script>
<style>
.item_box_jbxx .el-collapse-item__header {
  height: 0.55rem;
  background: #1954a4;
  font-size: 0.2rem;
  font-weight: bold;
  color: #ffffff;
  padding-left: 0.3875rem;
  box-sizing: border-box;
}
.item_box_jbxx .el-collapse-item:last-child .el-collapse-item__content {
  padding-bottom: 0px;
}
.item_box_jbxx {
  margin-left: 0.625rem;
}
.item_box_jbxx .el-descriptions .is-bordered .el-descriptions-item__label {
  text-align: center !important;
}
</style>
<style scoped>
.button_box_jb {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.2625rem;
  margin-left: 0.8875rem;
  padding-bottom: 0.5rem;
}
.button_box_jb_w div {
  margin-left: 0.3125rem;
  margin-right: 0 !important;
}
.button_box_jb div {
  margin-right: 0.3125rem;
}
.button_box_jb .zc,
.xyb,
.hs {
  width: 1.25rem;
  height: 0.5rem;
  background: #1954a4;
  border-radius: 0.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.2rem;
  font-weight: 400;
  color: #ffffff;
}
.hs {
  background: #7c7c7c;
}
.button_box_jb .zc:hover {
  background: #1f5fb8;
  cursor: pointer;
}
.button_box_jb .xyb {
  background: #fca204;
  cursor: pointer;
}
.button_box_jb .xyb:hover {
  background: #e9a125;
  cursor: pointer;
}
</style>
